﻿using System;
using System.IO;

namespace CommonLibrary.Helpers
{
    public static class LogSystem
    {
        private const string LogFile = "Log.txt";
        static object locker = new object();

        public static void LogMessage(string message)
        {
            WriteMessage(message);
        }

        public static void LogErrorMessage(string message)
        {
            WriteMessage(message, TypeOfMessage.Critica);
        }

        private static void WriteMessage(string message, TypeOfMessage severity = TypeOfMessage.None)
        {
            lock (locker)
            {

                switch (severity)
                {
                    case TypeOfMessage.Critica:
                        message = "[Critical] " + message;
                        break;
                    case TypeOfMessage.Normal:
                        message = "[Normal] " + message;
                        break;
                    case TypeOfMessage.Regular:
                        message = "[Information] " + message;
                        break;
                }
                File.AppendAllText(LogFile, Environment.NewLine + message);
            }
        }

        private enum TypeOfMessage
        {
            Critica,
            Normal,
            Regular,
            None
        }
    }
}
